'use strict'

define(['jquery', 'bootstrap'], function($) {
  
  return {
    
    init: function() {
      this.initPage();
      this.submit();
    },
    
    initPage: function(){
      
      $(document).on('click','#select-all', function(e){
        var $selectAll = $('#select-all');
        $('input[name="dispatchOrderIds"]').prop('checked', $selectAll.is(':checked'));
      });
      
    },
    
    submit: function() {
      $(document).on('click', 'button[type="submit"]', function(e) {
        
        e.preventDefault();
        
        var submit = false;
        $('input[name="dispatchOrderIds"]:checked').each(function() {
          submit = true;
          return false;
        });
        
        if (submit === false) {
          $('div.invalid-message').show();
          setTimeout(function() {
            $('div.invalid-message').hide();
          }, 3000);
        } else {
          $('form').submit();
        }
        
      });
    }
              
  }
  
})